from db import utils
from logger import logger
from sub_events.base_event import BaseEvent

LOGGER = logger.CustomLogger()

class UpdateOwnerPass(BaseEvent):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.event_name_zh: str = "记录加分"
        self.event_name_en: str = "Record Review"

    def pre_execute(self) -> bool:
        return self.hook.commenter in self.OCM.owner_config['userInfos']

    def execute(self) :
        user_infos = self.OCM.owner_config['userInfos']
        group_info = user_infos[self.hook.commenter]['group']
        comment = ""
        if isinstance(group_info, list):
            for group in group_info:
                if utils.update_code_owner_pass(self.hook, group):
                    comment += f"@{group} 加分已记录。\n\n"
        if comment:
            comment += "若本次加分失败，请您在所有管控项通过后，评论\"self check\"可恢复加分，无需再找CodeOwner进行加分。\n\n"
            comment += "If the current review fails, you can restore the review by commenting 'self check' once all check items are passed. No further action from the CodeOwner is required."
        self.comment += comment
